<template>
  <div class="login-page">
    <div class="login-box">
      <h3>客户管理系统登录</h3>
      <el-form
        ref="ruleFormRef"
        :model="form"
        status-icon
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm">
        <el-form-item label="用户名" prop="user">
          <el-input v-model="form.username" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="form.password"
            type="password"
            autocomplete="off"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import http from "../request/index.js";
import { useUserStore } from "../stores/user.js";
export default {
  data() {
    return {
      form: {
        username: "admin",
        password: "123456",
      },
      rules: {},
    };
  },
  computed: {
    user() {
      return useUserStore();
    },
  },
  methods: {
    async login() {
      let res = await http.post("/api/permission/getMenu", this.form);
      res = res.data;
      console.log("!!!", res);
      if (res.code === 20000) {
        //设置登录标记
        this.user.token = res.data.token;
        console.log(res.data.menu);
        this.$router.push({ path: "/home" });
      } else {
        this.$message.warning(res.data.message);
      }
    },
    // login() {
    //   this.$router.push("/home");
    // },
  },
};
</script>

<style lang="scss" scoped>
.login-page {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("../assets/images/bg.png");
  background-repeat: no-repeat;
  .login-box {
    width: 400px;
    background-color: #fff;
    border-radius: 10px;
    padding-top: 10px;
    padding-right: 50px;
    padding-bottom: 20px;
    h3 {
      text-align: center;
      margin-bottom: 20px;
      padding-left: 40px;
    }
  }
}
</style>
